package view.client;


import control.client.GroupManagementAction;
import control.client.MemberManagementAction;
import control.client.InstructionAction;
import java.awt.BorderLayout;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.JTextField;
import util.IConstant;

/**
 *
 * @author S3224743
 */
public class SettingPanel extends javax.swing.JPanel
{
    //private fields
    private static SettingPanel settingPanel;
    private GroupManagementAction groupMgmtAction;
    private MemberManagementAction memberMgmtAction;


    //private fields
    private BaseClient baseClient;
    private InstructionAction welcomeMessageAction;

    //private Constructor
    public SettingPanel(BaseClient baseClient)
    {
        this.initComponents();

        //Initialized
        this.baseClient=baseClient;
        this.groupMgmtAction = new GroupManagementAction(this);
        this.memberMgmtAction = new MemberManagementAction(this);
        this.welcomeMessageAction=new InstructionAction(this);

        //okGroupsBtn
        this.okGroupsBtn.setActionCommand(IConstant.GROUP_MGMT_BUTTON);
        this.okGroupsBtn.addActionListener(groupMgmtAction);

        //okMemberBtn
        this.okMemberBtn.setActionCommand(IConstant.MEMBER_MGMT_BUTTON);        
        this.okMemberBtn.addActionListener(memberMgmtAction);       

        //updateWelcomeBtn
        this.updateWelcomeBtn.addMouseListener(welcomeMessageAction);
    }

    //public static methods
    public static SettingPanel getInstance(BaseClient baseClient)
    {
        if(settingPanel==null)
            settingPanel=new SettingPanel(baseClient);
        return settingPanel;
    }

    //properties
    public BaseClient getBaseClient()
    {
        return baseClient;
    }

    public JComboBox getGroupsCmbBox()
    {
        return groupsCmbBox;
    }

    public JTable getGroupsTable()
    {
        return groupsTable;
    }

    public JComboBox getMemberCmbBox()
    {
        return memberCmbBox;
    }

    public JTable getMemberTable()
    {
        return memberTable;
    }

    public JButton getOkGroupsBtn()
    {
        return okGroupsBtn;
    }

    public JButton getOkMemberBtn()
    {
        return okMemberBtn;
    }

    public JButton getUpdateWelcomeBtn()
    {
        return updateWelcomeBtn;
    }

    public void setGroupsTable(JTable groupsTable)
    {
        this.groupsTable = groupsTable;
    }

    public JTextField getWelcomeTxtField()
    {
        return welcomeTxtField;
    }

    public void setMemberTable(JTable memberTable)
    {
        this.memberTable = memberTable;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        welcomeTxtField = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        updateWelcomeBtn = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        membersPanel = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        memberCmbBox = new javax.swing.JComboBox();
        okMemberBtn = new javax.swing.JButton();
        membersTablePanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        memberTable = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        groupsPanel = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        groupsCmbBox = new javax.swing.JComboBox();
        okGroupsBtn = new javax.swing.JButton();
        groupsTablePanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        groupsTable = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout(10, 0));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Welcome Message", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N
        jPanel1.setMaximumSize(new java.awt.Dimension(32767, 80));
        jPanel1.setMinimumSize(new java.awt.Dimension(100, 80));
        jPanel1.setPreferredSize(new java.awt.Dimension(494, 80));
        jPanel1.setLayout(new java.awt.BorderLayout(10, 5));

        welcomeTxtField.setFont(new java.awt.Font("Tahoma", 0, 14));
        welcomeTxtField.setText("Hi, %s! Welcome to the Discussion Board");
        welcomeTxtField.setPreferredSize(new java.awt.Dimension(72, 25));
        jPanel1.add(welcomeTxtField, java.awt.BorderLayout.CENTER);

        updateWelcomeBtn.setText("Update");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(updateWelcomeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(updateWelcomeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
        );

        jPanel1.add(jPanel7, java.awt.BorderLayout.LINE_END);

        add(jPanel1, java.awt.BorderLayout.PAGE_START);
        this.jPanel1.add(Box.createHorizontalStrut(5),BorderLayout.WEST);
        this.jPanel1.add(Box.createVerticalStrut(8),BorderLayout.NORTH);
        this.jPanel1.add(Box.createVerticalStrut(8),BorderLayout.SOUTH);

        jPanel2.setLayout(new java.awt.GridLayout(2, 0, 5, 5));

        membersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Members", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N
        membersPanel.setLayout(new javax.swing.BoxLayout(membersPanel, javax.swing.BoxLayout.Y_AXIS));

        jPanel8.setPreferredSize(new java.awt.Dimension(506, 50));

        memberCmbBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "Delete" }));

        okMemberBtn.setText("Ok");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(memberCmbBox, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(okMemberBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(486, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(memberCmbBox, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(okMemberBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        membersPanel.add(jPanel8);

        membersTablePanel.setLayout(new java.awt.BorderLayout());

        memberTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "", "ID", "Username", "Password", "Level", "Block"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(memberTable);

        membersTablePanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        membersPanel.add(membersTablePanel);
        membersTablePanel.add(Box.createHorizontalStrut(10),BorderLayout.WEST);
        membersTablePanel.add(Box.createHorizontalStrut(10),BorderLayout.EAST);
        membersTablePanel.add(Box.createVerticalStrut(10),BorderLayout.NORTH);
        membersTablePanel.add(Box.createVerticalStrut(10),BorderLayout.SOUTH);

        jPanel2.add(membersPanel);

        jPanel4.setLayout(new java.awt.GridLayout(1, 2, 5, 5));

        groupsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Groups"));
        groupsPanel.setLayout(new javax.swing.BoxLayout(groupsPanel, javax.swing.BoxLayout.Y_AXIS));

        jPanel3.setPreferredSize(new java.awt.Dimension(355, 50));

        groupsCmbBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "Delete" }));
        groupsCmbBox.setPreferredSize(new java.awt.Dimension(118, 22));

        okGroupsBtn.setText("Ok");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(groupsCmbBox, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(okGroupsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(491, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(groupsCmbBox, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(okGroupsBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        groupsPanel.add(jPanel3);

        groupsTablePanel.setLayout(new java.awt.BorderLayout());

        groupsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "", "ID", "Name", "Description", "Approved"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(groupsTable);

        groupsTablePanel.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        groupsPanel.add(groupsTablePanel);
        groupsTablePanel.add(Box.createHorizontalStrut(10),BorderLayout.WEST);
        groupsTablePanel.add(Box.createHorizontalStrut(10),BorderLayout.EAST);
        groupsTablePanel.add(Box.createVerticalStrut(10),BorderLayout.NORTH);
        groupsTablePanel.add(Box.createVerticalStrut(10),BorderLayout.SOUTH);

        jPanel4.add(groupsPanel);

        jPanel2.add(jPanel4);

        add(jPanel2, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox groupsCmbBox;
    private javax.swing.JPanel groupsPanel;
    private javax.swing.JTable groupsTable;
    private javax.swing.JPanel groupsTablePanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox memberCmbBox;
    private javax.swing.JTable memberTable;
    private javax.swing.JPanel membersPanel;
    private javax.swing.JPanel membersTablePanel;
    private javax.swing.JButton okGroupsBtn;
    private javax.swing.JButton okMemberBtn;
    private javax.swing.JButton updateWelcomeBtn;
    private javax.swing.JTextField welcomeTxtField;
    // End of variables declaration//GEN-END:variables
}
